package com.abel.bigwater.data.kente

import com.abel.bigwater.data.mapper.DataMapper
import com.abel.bigwater.data.mapper.RtuMapper
import io.netty.buffer.Unpooled
import io.netty.channel.embedded.EmbeddedChannel
import io.netty.channel.socket.DatagramPacket
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import java.net.InetSocketAddress

@SpringBootTest
@RunWith(SpringRunner::class)
class KenteUdpHandlerTests {
    @Autowired
    var rtuMapper: RtuMapper? = null

    @Autowired
    var dataMapper: DataMapper? = null

    var firmId = "23"

    var firmCode = "lt-"

    var firmName = "测试"

    @Test
    fun testUdp1() {
        val str = "ADDRESS:001 NAME:10001062 FTOTAL:0000423361.9070M3 RTOTAL:0000000074.2690M3 FLOW:+37.1371M3/h SPEED:0.3283m/s TUB:00000% ALARM:550000000 CSQ:25 TIME:2018-07-25 16:30:05 PRESS:0.3131MPa"
        val ch = EmbeddedChannel(KenteUdpHandler(dataMapper!!, rtuMapper!!, firmId, firmCode))
        ch.writeInbound(DatagramPacket(Unpooled.buffer().writeBytes(str.toByteArray()), InetSocketAddress("localhost", 9527)))

        Thread.sleep(1000)
    }

}